﻿//======================================================
//==     (c)2008 aspxcms inc by NeTCMS v1.0              ==
//==          Forum:bbs.aspxcms.com                   ==
//==         Website:www.aspxcms.com                  ==
//======================================================
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NetCMS.Content;

public partial class manage_menu : NetCMS.Web.UI.ManagePage
{
    UserMisc rd = new UserMisc();
    Channel md = new Channel();
    public string stype = "";
    public string SiteList = string.Empty;
    public string IsSuper = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        #region 读取会员拥有权限的栏目
        NetCMS.Content.AdminGroup agc = new NetCMS.Content.AdminGroup();
        IsSuper = agc.GetAdminIsSuper(this.UserNum);

        if (IsSuper!= "1")//判断是不是超级管理员
        {
            string adminGroupNumber = agc.getAdminGroup(this.UserNum);
            IDataReader rdg = agc.getAdminGroups(adminGroupNumber);
            while (rdg.Read())
            {
                if (!rdg.IsDBNull(2))
                {
                    SiteList = rdg.GetString(2);
                }
            }
            rdg.Close();
        }
        #endregion

        if (!IsPostBack)
        {
            stype = Request.QueryString["type"];
        }
        string type = Request.QueryString["Type"];
        if (type == null)
        {
            Response.Redirect("index.aspx");
        }
       // shortcut_id.InnerHtml = ShortcutList(rd.ShortcutList(UserNum, 1));
        string getChStr = Request.QueryString["CH"];
        if (getChStr != string.Empty && getChStr != null)
        {

        }
        else
        {
            menuNavi_id.InnerHtml = menuNavilist(type);
        }
    }

    protected string ShortcutList(IDataReader rd)
    {
        string qflg = "\r<div>\r";
        int i = 0;
        while (rd.Read())
        {
            string QMID = rd["QMID"].ToString();
            string qName = rd["qName"].ToString();
            string FilePath = rd["FilePath"].ToString();
            string usernum = rd["usernum"].ToString();
            qflg = qflg + " <li onmouseover=\"javascript:setshorcutmenu('none');\" style=\"list-style:none;padding-left:5px;\"><img src='../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/admin/menu_dot_21.gif' alt=\"\" border=\"0\">";
            qflg = qflg + "<a class=\"menulist\" href=\"" + FilePath + "\" target=\"sys_main\">" + qName + "</a></li>";
            i++;
        }
        rd.Close();
        if (i < 1)
        {
            qflg = qflg + "<li style=\"list-style:none;padding-left:5px;\">无快捷方式，<a href=\"sys/shortcut_list.aspx\" target=\"sys_main\"><font color=\"red\">创建</font></a></li>";
        }
        qflg = qflg + "</div>\r";
        return qflg;
    }

    protected string menuNavilist(string type)
    {
        string liststr = "\r<div>\r";
        switch (type)
        {
            case "0"://内容管理
                liststr += checkPr("C000", "news/class_site.aspx", "menu", "新闻管理");
                liststr += checkPr("C019", "news/class_list.aspx", "sys_main", "栏目管理");
                liststr += checkPr("C038", "news/special_list.aspx", "sys_main", "专题管理");
                liststr += checkPr("C042", "Contribution/Constr_List.aspx", "sys_main", "稿件管理");
                liststr += checkPr("C048", "news/History_manage.aspx", "sys_main", "归档管理");
                liststr += checkPr("CE02", "news/unnews.aspx", "sys_main", "不规则新闻管理");
                liststr += checkPr("C051", "js/JS_List.aspx", "sys_main", "JS管理");
                liststr += checkPr("C055", "js/Js_Templet.aspx", "sys_main", "JS模型");
                break;
            case "1"://频道管理
                liststr += checkPr("C034", "channel/list.aspx", "sys_main", "频道列表");
                liststr += checkPr("C035", "channel/channel_add.aspx", "sys_main", "创建频道");
                liststr += checkPr("C058", "news/site_list.aspx", "sys_main", "站群管理");
                break;
            case "2"://发布管理
                liststr += checkPr("T001", "Templet/Manage_List.aspx", "sys_main", "模板管理");
                liststr += checkPr("T010", "label/syslabel_list.aspx", "sys_main", "标签管理");
                liststr += checkPr("T008", "label/freelabel_list.aspx", "sys_main", "自由标签管理");
                liststr += checkPr("T017", "label/style.aspx", "sys_main", "样式管理");
                liststr += checkPr("B003", "Publish/site.aspx", "sys_main", "发布站点");
                liststr += checkPr("P005", "Publish/siteTask.aspx", "sys_main", "计划任务");
                liststr += checkPr("P009", "Publish/psf.aspx", "sys_main", "PSF接点");
                liststr += checkPr("P013", "Publish/logs.aspx", "sys_main", "发布日志");
                break;
            case "3"://会员中心
                liststr += checkPr("U001", "user/userlist.aspx", "sys_main", "会员列表");
                liststr += checkPr("U011", "user/usergroup.aspx", "sys_main", "会员组管理");
                liststr += checkPr("U015", "user/userdiscuss_list.aspx", "sys_main", "讨论组管理");
                liststr += checkPr("U019", "user/announce.aspx", "sys_main", "公告管理");
                liststr += checkPr("U024", "user/icard.aspx", "sys_main", "点卡管理");
                liststr += checkPr("U028", "user/pointhistory.aspx", "sys_main", "充值记录");
                liststr += checkPr("U030", "user/onlinepay.aspx", "sys_main", "在线支付");
                liststr += checkPr("U033", "user/message.aspx", "sys_main", "短消息管理");
                liststr += checkPr("U034", "user/usermycom.aspx", "sys_main", "评论管理");
                break;
            case "4"://插件管理
                liststr += checkPr("S006", "advertisement/list.aspx", "sys_main", "广告系统");
                liststr += checkPr("S008", "collect/collect_list.aspx", "sys_main", "采集系统");
                liststr += checkPr("S005", "Survey/VoteTopic.aspx", "sys_main", "问卷调查");
                liststr += checkPr("S014", "Friend/Friend_List.aspx?type=link", "sys_main", "友情链接");
                liststr += checkPr("S001", "Stat/View.aspx?type=class", "sys_main", "统计系统");
                liststr += checkPr("Q030", "adapt/adapt.aspx", "sys_main", "整合接口");
                liststr += checkPr("Q031", "sys/checkFiles.aspx", "sys_main", "文件对比");
                liststr += checkPr("Q020", "sys/File_GetIn.aspx", "sys_main", "文件管理");
                liststr += checkPr("Q032", "sys/DefineTable_Manage.aspx", "sys_main", "自定义字段");
                liststr += checkPr("S016", "sys/customform.aspx", "sys_main", "自定义表单");
                liststr += checkPr("Q024", "sys/database.aspx", "sys_main", "数据库维护");
                break;
            case "5"://控制面板
                liststr += checkPr("Q018", "sys/General_manage.aspx", "sys_main", "常规管理");
                liststr += checkPr("Q001", "sys/sys_Param.aspx", "sys_main", "参数设置");
                liststr += checkPr("Q009", "sys/const.aspx", "sys_main", "配置文件");
                liststr += checkPr("Q010", "sys/admin_list.aspx", "sys_main", "管理员列表");
                liststr += checkPr("Q016", "sys/admin_group.aspx", "sys_main", "管理员组");
                liststr += checkPr("Q027", "news/recyle.aspx", "sys_main", "回收站管理");
                liststr += checkPr("U031", "user/arealist.aspx", "sys_main", "地区管理");
                liststr += checkPr("Q022", "../user/info/logs.aspx", "sys_main", "日程安排");
                liststr += checkPr("Q025", "sys/navimenu_list.aspx", "sys_main", "功能菜单");
                //liststr += checkPr("Q029", "sys/shortcut_list.aspx", "sys_main", "快捷方式");
                break;
        }

        this.Authority_Code = "D001";
        if (CheckAuthority())
        {
            channelDivMenu.InnerHtml = GetModelMenu(0, 0);
        }
        liststr += "</div>";
        return liststr;
    }

    protected string GetModelMenu(int ParentID,int Layer)
    {
        string listchmenu = string.Empty;
        IDataReader drs = md.getModelTemplet(ParentID);
        while (drs.Read())
        {
            
            string stxt = "";
            if (Layer > 0)
            {
                stxt = "┞┄ ";
            }

            if (IsSuper=="1")
            {
                listchmenu += "<li style=\"list-style:none;\">" + stxt + "<img src='../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/admin/menu_dot_21.gif' alt='' border='0'><a class=\"menu_ctr\" href=\"channel/read.aspx?ChID=" + drs["ID"].ToString() + "\" target=\"menu\">" + drs["channelName"].ToString() + "</a></li>\r";
            }
            else
            {
                if(SiteList.IndexOf(drs["ID"].ToString()) >= 0)
                {
                    listchmenu += "<li style=\"list-style:none;\">" + stxt + "<img src='../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/admin/menu_dot_21.gif' alt='' border='0'><a class=\"menu_ctr\" href=\"channel/read.aspx?ChID=" + drs["ID"].ToString() + "\" target=\"menu\">" + drs["channelName"].ToString() + "</a></li>\r";
                }
            }
            listchmenu += GetModelMenu(int.Parse(drs["ID"].ToString()), (Layer + 1));
        }
        drs.Close();
        return listchmenu;
    }

    /// <summary>
    /// 权限判断
    /// </summary>
    /// <param name="code">权限代码</param>
    /// <returns></returns>
    public string checkPr(string code, string Href, string Target, string Name)
    {
        this.Authority_Code = code;
        string str = string.Empty;
        if (CheckAuthority())
        {
            str += "<li style=\"list-style:none;padding-left:5px;\"><img src='../sysImages/default/admin/menu_dot_21.gif' alt='' border='0'><a class='menulist' href='"+Href+"' onmouseover=\"javascript:setshorcutmenu('none');\" target='"+Target+"'>"+Name+"</a></li>\r";
        }
        return str;
    }
}